<?php
/**
* @file Versionm.php
* @synopsis  idfa广告控制
* @author Yee, <rlk002@gmail.com>
* @version 1.0
* @date 2015-03-31 16:52:13
*/


class Versionm extends CI_Model
{
	function __construct()
	{
		parent::__construct();
	}

	public function get_readyForSale($query)
	{
		$this->db->select("ml_version.is_sale");
		$this->db->from("ml_version");
		$this->db->join("ml_product","ml_product.id = ml_version.pro_id","left");
		$this->db->where($query);
		$result = $this->db->get()->result_array();
		return $result[0]['is_sale'];
	}

	public function get_now_version($pro_id)
	{
		$key = "softupdateversion" . $pro_id;
		$result = $this->mc->get($key);
		if (is_bool($result) && $result == false) {
			$this->db->select("ml_version.*,ml_product.number as pro_number");
			$this->db->from("ml_version");
			$this->db->join("ml_product", "ml_version.pro_id = ml_product.id", "left");
			$this->db->where(array("ml_product.number" => $pro_id, "ml_version.is_show" => 1));
			$this->db->order_by("ml_version.version_code", "desc");
			$this->db->limit(1, 0);
			$result = $this->db->get()->row_array();
			/*echo $this->db->last_query();
            debug($result[0]);*/
			if ($pro_id && $result) {
				$this->mc->save($key, $result, 30 * 60);
			}
		}
		return $result;
	}
}
?>